export const transToLowerCase = function (data) {
    function getType(params) {
        return Object.prototype.toString.call(params).substring(8).replace(']', '')
    }

    function getKeys(obj, blank) {
        Object.keys(obj).forEach(key => {
            let low = key.replace(key[0], key[0].toLowerCase());
            let value = obj[key];
            let valueType = getType(value);
            if (valueType === 'Object') {
                blank[low] = {};
                getKeys(value, blank[low])
            } else if (valueType === 'Array') {
                blank[low] = [];
                getKeys(value, blank[low])
            } else {
                blank[low] = value;
                return blank
            }
        })
    }
    let blankObj = {};
    getKeys(data, blankObj)
    return blankObj;
}

export const transToUpperCase = function (data) {
    function getType(params) {
        return Object.prototype.toString.call(params).substring(8).replace(']', '')
    }

    function getKeys(obj, blank) {
        Object.keys(obj).forEach(key => {
            let low = key.replace(key[0], key[0].toUpperCase());
            let value = obj[key];
            let valueType = getType(value);
            if (valueType === 'Object') {
                blank[low] = {};
                getKeys(value, blank[low])
            } else if (valueType === 'Array') {
                blank[low] = [];
                getKeys(value, blank[low])
            } else {
                blank[low] = value;
                return blank
            }
        })
    }
    let blankObj = {};
    getKeys(data, blankObj)
    return blankObj;
}
export const hasQueryString = function (pathStr, name) {
    if (!pathStr.includes('?')) return false;
    var reg = new RegExp(name + "=([^&]*)(&|$)", "i");
    var r = pathStr.match(reg);
    if (r != null) return true;
    return false;
}

export const formatSeconds = function(value) {
    var theTime = parseInt(value)>0?parseInt(value):0;// 秒
    var middle= 0;// 分
    var hour= 0;// 小时

    if(theTime > 60) {
        middle= parseInt(theTime/60);
        theTime = parseInt(theTime%60);
        if(middle> 60) {
            hour= parseInt(middle/60);
            middle= parseInt(middle%60);
        }
    }
    middle = middle>=10?middle:`0${middle}`;
    hour =  hour>=10?hour:`0${hour}`;
    theTime = theTime>=10?theTime:`0${theTime}`;
    return {
        h:hour,
        m:middle,
        s:theTime
    };
}

export const handleInfo = function(val){ // 正则匹配掉结构
    if(val){
        let str = decodeURIComponent(val)
        let reg=/<\/?.+?\/?>/g;
        str = str.replace(reg,'');
        if(str.length>390){
            return str.substr(0,390)+"...";
        }else{
            return str=="null"?'暂无':str;
        }
    }else{
        return "暂无";
    }
}